****************************************************************************
* File-Nale: 		survey codes.do
* Date:		 07/22/2020
* Author: 		Fred Batista
* Purpose: 		Analysis of Brazilian Electoral Study (2010)
* Data used: 		survey.dta
* Data Output:	None	*/
****************************************************************************


***RECODING VARIABLES

*** Control variables

* sorting dataset

sort nquest

* state of residency

gen state = ESTADO

label variable state "State of residency"

* dummies for states (for fixed effects in models)

tab state, gen(state)

* urban residency

gen urban = 2 - ZONA

label variable urban "Resid�ncia urbana =1 (rural=0)"

* woman

gen woman = SEXO - 1

label variable woman "Woman"

* age

gen age = IDADE

label variable age "Age"

* education (transforming level in years of education)

gen education = ESC

recode education (1=0) (2=2) (3=4) (4=6) (5=8) (6=9.5) (7=11) (8=13) (9=15) (10=18)

label variable education "Years of education (from degree of education)"

* whether respondent works outside of home

gen jobmarket = SITUPROF

recode jobmarket (1/8 10=1) (else=0)

label variable jobmarket "Works outside home (SITUPROF recode)"

* Family income (less missing cases than personal income)

gen income = RENDAF

label variable income "Family income"

gen income_2 = income/510

label variable income_2 "Family income in minimum wages"

* campaign awareness

gen campaign = v82

recode campaign (5 6=.) (4=0) (3=1) (2=2) (1=3) 

label variable campaign "Campaign awareness"

* Newspaper reading

gen newspaper = v224

recode newspaper (.=0) (6=.) (4=1) (3=2) (2=3) (1=4)

label variable newspaper "Newspaper reading"

* race (dummies for white, brown, and black)

gen white = COR

recode white (1=1) (else=0)

gen black = COR

recode black (2=1) (else=0)

gen brown = COR

recode brown (3=1) (else=0)

* relgion (dummies for evangelical and catholic)

gen evangelical = RELIGI

recode evangelical (2 3=1) (else=0)

gen catholic = RELIGI

recode catholic (8=1) (else=0)


*** Attitudes and opinions (potentially related to the vote choice)

* if respondent is partisan

gen partisan = v40

recode partisan (1=1) (2 3=0) (4=.)

label variable partisan "Respondent identifies with a party (recode q40)"

* party preference (nominal)

gen partisanship = v41

recode partisanship (.=0) (29 30=0) (4 =5 ) (8=4) (1=3) (14=2) (else=1)

label define partisanshipl 0 "Nenhum" 1 "Outhers" 2 "PV" 3 "PMDB" 4 "PSDB" 5 "PT"

label values partisanship partisanshipl

* dummies for party ids

gen idpt = partisanship

recode idpt (5=1) (else=0)

gen idpsdb = partisanship

recode idpsdb (4=1) (else=0)

gen idpv = partisanship

recode idpv (2=1) (else=0)

* if respondents believes that president should identify with a party 

gen presparty = v165

recode presparty (1=1) (else=0)

label variable presparty "Resp thinks president should identify with a party"

* whether respondent locates herself in left-right scale

gen ideology = v79

recode ideology (0/10 = 1) (else=0)

label variable ideology "whether respondent locates herself in left-right scale"

* dummies for left, center, right

gen left = v79

recode left (0 1 2 3=1) (else=0)

label variable left "Left = 0, 1, 2 or 3"

gen center = v79

recode center (4 5 6=1) (else=0)

label variable center "Center = 4, 5 or 6"

gen right = v79

recode right (7 8 9 10=1) (else=0)

label variable right "Right = 7, 8, 9 or 10"


* economic evaluations

gen sociotropic = v234

recode sociotropic (1=4) (2=3) (3=2) (4=1) (5=0) (6=.)

label variable sociotropic "Sociotropic economic evaluation"

gen socioretro = v235

recode socioretro (1=2) (2=1) (3=0) (4=.)

label variable socioretro "Retrospective sociotropic economic evaluation"

gen pocketbook= v236

recode pocketbook (1=4) (2=3) (3=2) (4=1) (5=0) (6=.)

label variable pocketbook "Pocketbook economic evaluation"

gen pocketretro = v237

recode pocketretro (1=2) (2=1) (3=0) (4=.)

label variable pocketretro "Retrospective pocketbook economic evaluation"

* recipient of social programs

gen program1 = v241

gen program2 = v242

gen program3 = v243

gen program4 = v244

recode program1 program2 program3 program4 (1=1) (2=0) (3=.)

gen partprogram = program1 + program2 + program3 + program4

recode partprogram (0=0) (1 2 3 4=1)

label variable partprogram "Recipient of social program"


* Opinions about women in politics

gen career = v249

gen bettergov = v250

gen womenexp = v251

recode career better womenexp (1=0) (2=1) (5=2) (3=3) (4=4)

label variable career "Men better suited for political career"

label variable bettergov "Men govern better

label variable womenexp "Women less political experienced"

tab career [aweight=pesopop]

tab bettergov [aweight=pesopop]

tab womenexp [aweight=pesopop]

polychoric career bettergov womenexp

gen sexism = (career + womenexp + bettergov)/3

label variable sexism "Additive scale of sexism"

factormat r(R), factor(1) ml n(2000) 

factor career womenexp bettergov, ml factor(1)

predict fsexism

summarize fsexism

replace fsexism = (fsexism - r(min))/(r(max)-r(min))

label variable fsexism "Factor scores of sexism from 0 to 1"


* codify reasons (v214, v215):

tab v213 [aweight=pesopop]

gen womenmajoritarian = 2 - v213


**** vote choice

* vote first round

gen vote1 = v86

recode vote1 (1=3) (4=2) (6=1) (2 3 7 8=.) (10 11 12 13=.)

label define vote1l 1 "Marina" 2 "Serra" 3 "Dilma"

label values vote1 vote1l

label variable vote1 "Vote in 1st round (non voters and voters for other excluded, very small group): 

* vote runoff

gen vote2 = v96

recode vote2 (1=1) (2=0) (else=.)

label define vote2l 1 "Dilma" 0 "Serra"

label values vote2 vote2l

label variable vote2 "Vote 2nd round"

* voted for a woman for state representativel

recode v124 (39 48 52 68 72 79 82 85 91 103 108115 123 128 139 143 149 164 170 171 193 205 206 208 243 247 249 264 270 279 286 342 349 370 388 396 417 420 438 445 447 450 468 469 502 507 517 525 533 543 545 551 560 589 619 622 624 643 673 674 697 698 704 708 709 710 711 712 714 722 724 744=1) (97 173 185 212 299 340 375 376 471 559 727 759=-1) (.=-1) (else=0), gen(vfemest)

label variable vfemest "Voted for a women for state representativel"

recode v124 (97 173 185 212 299 340 375 376=.) (471 559 727 759=0) (.=0) (else=1), gen(select_vfemest)

label variable select_vfemest"Selection to vfemest"


* voted for a woman for House of Represesntatives

recode v116 (13 84 90 94 114 119 125 126 130 132 153 161 174 182 183 194 201 225 232 233 259 281 286 309 312 313 323 329 371 381 408 439 444 474 491 495 496 508 526 536 563 572 580 591 598 615 622 625 641 646 678=1) (73  162 198 210 349 455 539 557 675 693 694=-1) (.=-1) (else=0), gen (vfemfed)

label variable vfemfed "voted for a woman for House"

recode v116 (693 694=0) (.=0) (73  162 198 210 349 455 539 557 675=.) (else=1), gen(select_vfemfed)

label variable select_vfemfed "Selection to vfemfed"

* Voted for a woman for Senate

* first choice

recode v106 (12 32 41 47 50 54 71 76 110 121 191 192 193 200 202 207 214 218 222 231 237=1) (39 262 263=-1) (.=-1) (else=0), gen(vfemsen1)

label variable vfemsen1 "Voted for a woman for Senate first choice"

recode v106 (262 263=0) (.=0) (39=.) (else=1), gen(select_vfemsen1)

label variable select_vfemsen1 "Selection to vfemsen1"

* second choice

recode v107 (12 32 47 66 71 76 82 110 136 191 192 193 200 209 214 231 237=1) (262 264=-1) (.=-1) (else=0), gen(vfemsen2)

label variable vfemsen2 "Voted for a woman for Senate second choice"

recode v106 (262 263=0) (.=0) (else=1), gen(select_vfemsen2)

label variable select_vfemsen2 "Selection to vfemsen2"

* multinomial vote for woman for senate

gen vfemsen=.
replace vfemsen=2 if vfemsen1==1 & vfemsen2==0
replace vfemsen=1 if vfemsen1==0 & vfemsen2==1
replace vfemsen=0 if vfemsen1==0 & vfemsen2==0

label variable vfemsen "Vote for woman for Senate first and second choices"

*any vote for woman for senate

gen vfemsen_any=. if vfemsen1==-1 & vfemsen2==-1
replace vfemsen_any=1 if vfemsen1==1
replace vfemsen_any=1 if vfemsen2==1
replace vfemsen_any=0 if vfemsen1==0 & vfemsen2==0

label variable vfemsen_any "Vote for any woman for Senate"

gen select_vfemsen_any=vfemsen_any
recode select_vfemsen_any (0 1=1) (.=0)

label variable select_vfemsen_any "Selection to vfemsen_any"


* Vote for a woman for state governor

recode v97 (41 45 58 75 107 120 122 132 144 147 152=1) (169 170 171 172 =-1) (.=-1) (else=0), gen(vfemgov)

label variable vfemgov "Vote for a woman for state governor"

gen select_vfemgov=vfemgov
recode select_vfemgov(-1=0) (0 1=1) (.=0)

label variable select_vfemgov"Selection to vfemgov"


**States with no women running for governor:
AC AL AM AP BA MS MT PE PR RJ RO RR TO)

recode ESTADO (1 2 3 4 5 11 12 15 17 19 22 23 27=0) (else=1), gen(womengov)

label variable womengov "State has women running for governor"

**States with women running for senate:
* (from TSE data): AC AP DF MS MT PB PI RJ TO

recode ESTADO (1 3 7 11 12 14 18 19 27=0) (else=1), gen(womensen)

label variable womensen "State has women running for senate"

**States with 2 women running for senate:

recode ESTADO (4 5 6 17 21 23 26=1) (else=0), gen(womensen2)

label variable womensen2 "State has 2 women running for senate"


* States with larger samples

recode ESTADO (5 13 15 19 21 26=1) (else=0), gen(bigstate)

label variable bigstate "States with larger samples"


*** Information

* True of False battery

gen partyalck = v171

gen majoritarian = v173

recode partyalck majoritarian (2=1) (1 3=0) (4=.)

gen mandate = v172

gen partylula = v174

recode mandate partylula (1=1) (2 3=0) (4=.)

* party of leaders battery

gen partaecio = v175

recode partaecio (8=1) (else=0)

gen partmercadante = v176

recode partmercadante (4=1) (else=0)

gen partciro = v177

recode partciro (7=1) (else=0)

gen partsuplicy = v178

recode partsuplicy (4=1) (else=0)

gen partfhc = v179

recode partfhc (8=1) (else=0)

gen partitamar = v180

recode partitamar (1=1) (else=0)

gen partbornhausen = v181

recode partbornhausen (5=1) (else=0)

gen partanibal = v182

recode partanibal (8=1) (else=0)

gen partdirceu = v183

recode partdirceu (4=1) (else=0)

gen partsarney = v184

recode partsarney (1=1) (else=0)

gen partserra = v185

recode partserra (8=1) (else=0)

gen partlula = v186

recode partlula (4=1) (else=0)

gen partmaciel = v187

recode partmaciel (5=1) (else=0)

gen partmarina = v188

recode partmarina (14=1) (else=0)

gen parttemer = v189

recode parttemer (1=1) (else=0)

gen partsimon = v190

recode partsimon (1=1) (else=0)

gen partroseana = v191

recode partroseana (1=1) (else=0)

* dimensionality analysis (partylula, partciro e partbornhausen removed to colinearity)

tetrachoric partyalck majoritarian mandate partylula partaecio partmercadante partciro partsuplicy partfhc partitamar partbornhausen partanibal partdirceu partsarney partserra partlula partmaciel partmarina parttemer partsimon partroseana, posdef

factormat r(Rho), factor(1) ml n(1993)

* generating additive scale

gen information = (partyalck + majoritari + mandate + partylula + partaecio + partmercadante + partciro + partsuplicy + partfhc + partitamar + partbornhausen + partanibal + partdirceu + partsarney + partserra + partlula + partmaciel + partmarina + parttemer + partsimon + partroseana)

label variable information "Additive scale of political information"


***********  ANALISES ******
* use weight [pweight=pesopop]


* SELECTION TESTS

* Senate: full sample

probit select_vfemsen_any fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro i.state [pweight=pesopop] if womensen==1

* Senate: only sample in common with chamber vote

 probit select_vfemsen_any fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state4 state5 state6 state8 state9 state10 state13 state15 state16 state17 state20 state21 state22 state24 state25 state26 [pweight=pesopop] if vfemfed!=-1 & womensen==1


* Chamber: full sample

probit select_vfemfed fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state2 state3 state4 state5 state6 state7 state8 state9 state10 state11 state12 state13 state14 state15 state16 state17 state18 state19 state20 state21 state22 state24 state25 state26  [pweight=pesopop]

* Chamber: only sample in common with senate vote

probit select_vfemfed fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state4 state5 state6 state8 state9 state10 state13 state15 state16 state17 state20 state21 state22 state24 state25 state26 [pweight=pesopop] if vfemsen_any!=. & womensen==1




*** MAIN MODELS

probit vfemsen_any fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state2 state4 state5 state7 state8 state9 state10 state15 state16 state20 state21 state22 state26  [pweight=pesopop] if vfemfed!=-1 & vfemsen_any!=.

margins

margins, at(fsexism=(0(.25)1))

probit vfemfed fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state3 state5 state7 state8 state9 state10 state11 state13 state14 state15 state16 state17 state18 state19 state20 state21 state22 state23 state24 state26 state27 [pweight=pesopop] if vfemfed!=-1 & vfemsen_any!=.

margins

margins, at(fsexism=(0(.25)1))

* graphing

* ATE

matrix prob = (.2639311\.0973761)

matrix probmin = (.2255753\ .0655803)

matrix probmax = ( .3022868\ .129172)

matrix office = (0\1)

matrix hte1 = prob, probmin, probmax, office

svmat hte1, names(a)

eclplot a1 a2 a3 a4, ciopts(blcolor(black) msize(vtiny)) estopts(color(black)) ytitle("") xtitle(Legislative Office, size(large) margin(medsmall)) xlabel(-.5 " " 0 "Senate" 1 "Chamber" 1.5 " ", noticks labsize(medium)) ylabel(0 ".00" .10 ".10" .20 ".20" .30 ".30" .40 ".40",nogrid) title("Predicted Probability of Vote" "for Female Candidate", color(black) size(large)) yscale(noextend)  plotregion(style(none)  margin(medlarge)) graphregion(color(white)  margin(medlarge)) ysize(8) xsize(8) saving(esebmain)


* HTE

matrix diff = (-.2166134\-.1689004\-.1249146\-.0855926\-.0515989)

matrix diffmin = (-.2896489\-.219736\-.1905662\-.1797696\-.1724533)

matrix diffmax = (-.1435779\-.1180658\-.059263\.00858443\.06925549)

matrix sexism = (0\1\2\3\4)

matrix hte2 = diff, diffmin, diffmax, sexism

svmat hte2, names(b)

eclplot b1 b2 b3 b4, eplot(co) ciopts(blcolor(black) msize(vtiny)) estopts(color(black)) ytitle("")  xtitle("Explicit Sexism", size(large) margin(medsmall)) xlabel(0 "Lowest" 1 " " 2 " " 3 " " 4 "Highest", labsize(medium)) ylabel(-.3 "-.30" -.2 "-.20" -.1 "-.10" 0 ".00" .1 ".10" ,nogrid) title("Predicted Treatment Effect" "on Vote for Female Candidate", color(black) size(large)) yline(0, lcolor(black) lpattern(dash)) yscale(noextend)  plotregion(style(none) margin(medlarge)) graphregion(color(white) margin(medlarge)) ysize(8) xsize(8) saving(esebmarg)

graph combine esebmain.gph esebmarg.gph, title(Survey Data (n=729), color(black) size(vlarge) pos(6)) ysize(6) xsize(10) iscale(1) graphregion(color(white) margin(medium)) saving(esebcomb)

graph export esebcomb.pdf


*** Robustness check: full data

probit vfemsen_any fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state2 state4 state5 state7 state8 state9 state10 state15 state16 state20 state21 state22 state26  [pweight=pesopop] if vfemsen_any!=-1


probit vfemfed fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state3 state5 state7 state8 state9 state10 state11 state13 state14 state15 state16 state17 state18 state19 state20 state21 state22 state23 state24 state26 state27 [pweight=pesopop] if vfemfed!=-1

*** State-level models

probit vfemgov fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state7 state8 state10 state18 state20 state21 state24 [pweight=pesopop] if vfemgov!=-1 & vfemest!=-1

probit vfemest fsexism information idpt idpsdb idpv left center right evangelical catholic campaign newspaper partprogram urban education jobmarket woman age white socioretro pocketretro state2 state3 state4 state5 state6 state7 state8 state9 state10 state13 state14 state15 state16 state17 state18 state19 state20 state21 state22 state23 state25 state26 state27 [pweight=pesopop] if vfemest!=-1 &vfemgov!=-1



*** END OF CODE
